package com.spark.tags;

import java.util.Map;

import com.spark.core.SparkContext;
import com.spark.core.XMap;

public class CheckBox extends ViewComponent {
	
	private static final String DEFAULT_TEMPLATES = "checkBox.ftl";
	
	public static final String PROPERTITY_CHECKEDVALUE = "checkedValue";
	public static final String PROPERTITY_UNCHECKEDVALUE = "unCheckedValue";
	public static final String PROPERTITY_LABEL = "label";
	
	public String getTemplate() {
		return DEFAULT_TEMPLATES;
	}
	
	
	public void init(XMap view, SparkContext context) throws Exception {
		super.init(view, context);
		context.put(PROPERTITY_LABEL, view.getString(PROPERTITY_LABEL,""));
	}
	
	@SuppressWarnings("unchecked")
	protected String build(SparkContext context){		
		Map map = context.getMap();
		StringBuilder sb = new StringBuilder();
		sb.append("<DIV class=\"").append(get(map,"className")).append("\" style=\"line-height:20px;height:20px;").append(get(map,"style")).append(";\" id=\"").append(get(map,"id")).append("\">");
		sb.append("    <DIV tabIndex=\"").append(get(map,"tabIndex")).append("\" hideFocus class=\"s-ckb\" stype=\"checkbox\">");
		sb.append("        <div class=\"s-ckb-box\"></div>");
		sb.append("    </DIV>");
		sb.append("    <label class=\"s-ckb-label\">").append(get(map,"label")).append("</label>");
		sb.append("</DIV>");
		sb.append("<script>new Spark.CheckBox(").append(get(map,"config")).append(");</script>");
		return sb.toString();
	}

}
